package org.nerve.bigFileIO.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * org.nerve.bigFileIO
 * Created by zengxm on 2016/8/24.
 */
public class MysqlConnector {
	protected String url;
	protected String user;
	protected String password;

	protected Connection connection;

	public MysqlConnector(){}

	public MysqlConnector(String url,String user,String password){
		this.url=url;
		this.user=user;
		this.password=password;
	}

	protected void initConnection() throws SQLException {
		if(connection==null){
			connection= DriverManager.getConnection(url, user, password);
		}
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Connection getConnection() throws SQLException {
		initConnection();
		return connection;
	}

	public void setConnection(Connection connection) {
		this.connection = connection;
	}

	public void closeConnection() throws SQLException {
		if(connection!=null)
			connection.close();
	}
}
